<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计算器</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="app">
        <input type="text" v-model="num1">
        <select v-model="opt">
            <option>+</option>
            <option>-</option>
            <option>*</option>
            <option>/</option>
        </select>
        <input type="text" v-model="num2">
        <button @click="equal">=</button>
        <input type="text" v-model="result">
    </div>
</body>
<script>
    let vm = new Vue({
        el : "#app",
        data : {
            num1 : 0,
            num2 : 0,
            opt : "-",
            result : 0
        },
        methods : {
            equal(){
                let optstr = "Number(this.num1)"+this.opt+"Number(this.num2)"
                //eavl()将字符串转换为代码
                this.result = eval(optstr)
            }
        }
    })
</script>
</html>